<template>
  <div>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      background
      :page-sizes="[5, 10, 15, 20]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      :url="url"
    />
  </div>
</template>

<script>
import { getTableData } from "../../utils/table";
export default {
  props: {
    total: Number,
    url: String,
  },
  data() {
    return {
      page: 1, //当前的页数
      size: 10,
    };
  },
  created() {
    //this.$parent 父级的 this
    getTableData(this.$parent, "/works", { page: this.page, size: this.size }, [
      "completed",
    ]);
  },
  methods: {
    handleSizeChange(val) {
      this.size = val;
      this.page = 1;
      getTableData(this.$parent, "/works", { page: this.page, size: val }, [
        "completed",
      ]);
    },
    handleCurrentChange(val) {
      this.page = val;
      getTableData(this.$parent, "/works", { page: val, size: this.size }, [
        "completed",
      ]);
    },
  },
};
</script>